layui.use(['Api', 'echarts', 'request'], function () {
	let echarts = layui.echarts;
    var Api = layui.Api,
        request = layui.request;

	var column4 = echarts.init(document.getElementById('column4'));
    var option = {
		title: {
			text: '线索来源',
			subtext: '种类分布',
			left: 'center'
		},
		tooltip: {
			trigger: 'item',
			formatter: '{a} <br/>{b} : {c} ({d}%)'
		},
		legend: {
			show: true,
			orient: 'horizontal',
			x: 'center',
			y: 'bottom',
		},
		grid: {
			top: 'bottom',
			left: '90',
			width: '90%',
			height: '80%',

		},
		series: [
			{
				name: '线索来源',
				type: 'pie',
				selectedMode: 'single',
				radius: ['30%', '55%'],
				data: [
					{ value: 210, name: '来信' },
					{ value: 510, name: '来电' },
					{ value: 100, name: '来访' },
				]
			}
		]
	};
	
	// column4.setOption(option);
	var success = function(res){
        let data_tmp = []
        for(var i in res.data.reportTypeNameList){
            data_tmp.push({
                value: res.data.reportTypeCount[i],
                name: res.data.reportTypeNameList[i]
            })
        }
        option.series[0].data = data_tmp
        column4.setOption(option);
    }
	var params = {
        isValid: layui.data('consoleSelect').item
    }
    request.get(Api.countReportType, params, success)

	window.onresize = function() {
		column4.resize();
	}
})
